<!--拌和站---拌合站设置-->
<!--
 * @Author: 卡卡 1071780426@qq.com
 * @Date: 2022-12-06 13:13:25
 * @LastEditors: 贺楠 1071780426@qq.com
 * @LastEditTime: 2024-08-08 10:03:42
 * @FilePath: \backstage - 副本\src\views\aa.vue
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
-->
<template>
  <div class="department" id="mixingPlant">
    <!-- 左侧部门管理 -->
    <div class="structureTree" v-if="treelength">
      <div class="structureTree_title">
        <div>组织机构</div>
        <div></div>
      </div>
      <tree
        :treeData="treeData"
        :checkData="checkData"
        name="waterManage_treeCheck"
        nodeKey="fCompanyid"
        @getTreeInfo="handleNodeClick"
        :defaultProps="defaultProps"
      >
      </tree>
    </div>
    <!-- 右侧 -->
    <div class="department_right">
      <!-- 机构名称 -->
      <el-breadcrumb :title="showName"></el-breadcrumb>
      <!-- 顶部导航栏 -->
      <div class="mechanism_nav">
        <!-- 左侧 -->
        <div class="mechanism_nav_left"></div>
        <!-- 顶部按钮 -->
        <div class="print" style="justify-content: flex-end">
          <!-- v-if="nature == '建设单位'" -->
          <el-button
            type="primary"
            v-if="yj_save"
            icon="el-icon-check"
            size="small"
            @click="yj_saveForm()"
            >保存
          </el-button>
        </div>
      </div>

      <!-- 表格 -->
      <div class="text_table editTableAlarm">
        <tableData
          :config="table_config"
          :currentRow="false"
          :dataList="tableData"
          :loading="listLoading"
          @inputValue="inputValue"
          statusType="1"
        />
      </div>
    </div>
  </div>
</template>
<script>
import tree from "@/components/stationProductionPage/waterManage/el-trees"; //左侧机构树
import TableData from "@/components/stationProductionPage/pitchManage/common/el-tables";
import elBreadcrumb from "@/components/public/el-breadcrumb.vue";
// import publicForm from "@/components/public/el-form.vue"
import {
  getUserCompanyTreeList, //树状图接口
  // saveAsphaltStationWarn, // 新增-沥青拌合站预警信息-温度时间新增接口
  // getAsphaltTemWarnByCompanyId, // 查询-沥青拌合站预警信息-温度时间详情接口

  // saveAsphaltMaterialWarn, // 保存
  saveWaterWarnMaterial,
  // getAsphaltMaterialWarnByCompanyId, //详情
  getWaterWarnMaterial,
} from "@/api/request.js";
import { statusType } from "@/utils/config"; //配置项
export default {
  name: "Home",
  data() {
    return {
      name: "swAlarmParameterSetting", //按钮配置页面代号
      nature: null,
      yj_save: null,
      formData: {}, //新增编辑向后台传递对象
      activeNames: ["0", "1"],
      // 拌和站列表配置项
      table_config: {
        classCell: true,
        thead: [
          {
            label: "",
            prop: "name",
            minWidth: "30px",
            filter: true,
            btn: true,
            align: "center",
            colorName: "",
            callback: (rowData) => {
              let data = statusType[rowData.name];
              if (data) {
                return data.label;
              }
            },
            specialClass: (rowData) => {
              let data = statusType[rowData.name];
              if (data) {
                return data.className;
              }
            },
          },
          {
            label: "水(%)",
            prop: "fOilstonewarn",
            minWidth: "30px",
            type: "number",
            disabled: false, //是否禁用
            edit: true,
            align: "center",
          },
          {
            label: "水泥(%)",
            prop: "fPitchwarn",
            minWidth: "30px",
            type: "number",
            disabled: false, //是否禁用
            edit: true,
            align: "center",
          },

          {
            label: "骨料(%)",
            prop: "fMineralwarn",
            minWidth: "30px",
            type: "number",
            disabled: false, //是否禁用
            edit: true,
            align: "center",
          },
          {
            label: "闭合流程",
            prop: "fExamine",
            minWidth: "60px",
            type: "option",
            disabled: false, //是否禁用
            option: true,
            align: "center",
            options: [
              {
                value: "无需闭合",
                label: "无需闭合",
              },
              {
                value: "一级流程",
                label: "一级流程",
              },
              {
                value: "二级流程",
                label: "二级流程",
              },
              {
                value: "三级流程",
                label: "三级流程",
              },
            ],
          },
          {
            label: "是否启用多级预警",
            prop: "fIsuse",
            minWidth: "45px",
            type: "radio",
            disabled: false, //是否禁用
            radio: true,
            align: "center",
          },
        ],
        isCheckBox: false,
        isIndex: false,
        isOperation: true,
      },

      temperatureStandard: [],
      search: "",
      tableData: [], //表格列表数据列表
      detailData: {}, //拌合站预警信息-详情
      highlightBd: true, //左侧机构树停留背景色
      treelength: false, //左侧树显示隐藏
      checked: true, //查看下级
      showName: "未选择公司",
      dialogHeight: "330px", //新增编辑弹框高度
      fId: null, //点击当前列表数据fId
      listLoading: false, //列表数据加载loading
      loadingEditDialog: false, //弹框loading
      dialogEditVisible: false, //新增弹框是否显示
      // 列表给后端传参
      getList: {
        companyId: "", // 施工标段id
      },

      companyTree: "", //所有数据
      treeData: [], //左侧树状图数据

      // 左侧机构树
      defaultProps: {
        children: "children",
        label: "fShortname",
      },
      userInfo: {}, //登录用户
      checkData: [],
      treeText: {
        //树状图参数
        companyId: null,
        userId: null,
        text: null,
      },
    };
  },
  components: {
    tree, //左侧组织机构数
    TableData, //主页面列表
    elBreadcrumb, //面包屑
    // publicForm,//弹框表格
  },
  mounted() {
    this.userInfo = JSON.parse(sessionStorage.getItem("yjSmart-userInfo"));
    if (JSON.parse(sessionStorage.getItem("yjSmart-waterManage_treeCheck"))) {
      var id = JSON.parse(sessionStorage.getItem("yjSmart-waterManage_treeCheck"));
      this.checkData = [id.fCompanyid];
    }
    this.getTree();
    this.btnRole(this.name);
  },
  methods: {
    btnRole(name) {
      // 按钮权限
      var btnList = [];
      var ModuleList = JSON.parse(sessionStorage.getItem("yjSmart-ModuleList"));
      if (ModuleList.length > 0) {
        ModuleList.map((item) => {
          if (item.fEncode == name) {
            btnList = item.modulebuttonList;
          }
        });
        var btnStr = [];
        btnList.map((item) => {
          btnStr.push(item.fEncode);
        });
        this.yj_save = btnStr.includes("yj_save");
      } else {
        this.yj_save = true;
      }
    },
    // 点击列表当前行，获取当前信息
    rowChange(row) {
      this.fId = row.fId;
    },
    // 左侧树结构
    getTree() {
      this.treeText = {
        companyId: this.userInfo.companyId,
        userId: this.userInfo.userId,
        text: "2", // 0其他  1 砼拌合站 2水稳 3沥青
      };
      getUserCompanyTreeList(this.treeText)
        .then((res) => {
          if (res.errcode == 0) {
            var companyTree = res.data.userCompanyTreeList;
            this.treeData = this.commonJs.tranListToTreeData(companyTree);
            if (this.treeData[0].children == undefined) {
              this.treelength = false; //左侧组织机构是否显示
            } else {
              this.treelength = true;
            }
            if (this.checkData[0]) {
              this.showName = JSON.parse(
                sessionStorage.getItem("yjSmart-waterManage_treeCheck")
              ).fShortname;
              this.getList.companyId = this.checkData[0];
            } else {
              this.checkData[0] = this.treeData[0].fCompanyid;

              this.showName = this.treeData[0].fShortname; //当前点击组织机构名称
              this.getList.companyId = this.treeData[0].fCompanyid; //当前点击组织机构ID
            }
            // this.yj_searchForm(this.getList, 0); // 调用主页面列表接口
            this.yj_searchForm(this.getList, 1); // 调用主页面列表接口
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch(() => {
          return false;
        });
    },

    // 点击左侧机构树
    handleNodeClick(data) {
      this.showName = data.fShortname; //顶部显示机构名
      this.getList.companyId = data.fCompanyid;
      this.nature = data.fNature;
      // this.yj_searchForm(this.getList, 0);
      this.yj_searchForm(this.getList, 1);
    },

    // 获取列表数据
    yj_searchForm(data, status) {
      console.log(status);
      this.listLoading = true;
      // 查询-沥青拌合站预警信息-温度时间详情接口
      // if (status == 0) {
      //   getAsphaltTemWarnByCompanyId(data)
      //     .then((res) => {
      //       if (res.errcode == 0) {
      //         console.log(res);
      //         var that = this;
      //         that.listLoading = false;
      //         this.temperatureStandard = res.data.warntemperature;
      //       } else {
      //         this.$message.error(res.msg);
      //         return false;
      //       }
      //     })
      //     .catch((error) => {
      //       console.log(error);
      //     });
      // } else if (status == 1) {
      // 查询-沥青拌合站预警信息-超标参数详情接口

      // getAsphaltMaterialWarnByCompanyId(data)
      getWaterWarnMaterial(data)
        .then((res) => {
          if (res.errcode == 0) {
            console.log("水稳", res);
            var that = this;
            that.listLoading = false;
            var list = res.data.warnMaterial;
            this.formData = list;
            this.detailData = res.data.warnMaterial;
            console.log("this.detailData", this.detailData);
            this.tableData = [
              {
                name: "1",
                fOilstonewarn: list.fWaterwarn1, //水 低预警
                fPitchwarn: list.fCementwarn1, //水泥 低预警
                fMineralwarn: list.fAggregatewarn1, //骨料 低预警
                fExamine: list.fExamine1, //闭合流程
                fIsuse: list.fIsuse, //1 是 0 否  是否启用
              },
              {
                name: "2",
                fOilstonewarn: list.fWaterwarn2, //水 低预警
                fPitchwarn: list.fCementwarn2, //水泥 低预警
                fMineralwarn: list.fAggregatewarn2, //骨料 低预警
                fExamine: list.fExamine2, //闭合流程
                fIsuse: list.fIsuse, //1 是 0 否  是否启用
              },
              {
                name: "3",
                fOilstonewarn: list.fWaterwarn3, //水 低预警
                fPitchwarn: list.fCementwarn3, //水泥 低预警
                fMineralwarn: list.fAggregatewarn3, //骨料 低预警
                fExamine: list.fExamine3, //闭合流程
                fIsuse: list.fIsuse, //1 是 0 否  是否启用
              },
            ];
          } else {
            this.$message.error(res.msg);
            return false;
          }
        })
        .catch((error) => {
          console.log(error);
        });
      // }
    },
    // 超标参数设置
    // yj_exceedStandard(data) {

    // },
    deleteUnqualifiedInfo(index) {
      this.temperatureStandard.splice(index, 1);
    },

    // 保存接口
    yj_saveForm() {
      // if (status == 0) {
      //   saveAsphaltStationWarn({
      //     companyId: this.getList.companyId,
      //     warntemperature: this.temperatureStandard,
      //   }).then((res) => {
      //     if (res.errcode == 0) {
      //       this.yj_searchForm(this.getList, 0);
      //       this.$message.success("拌和温度超标保存成功");
      //     } else {
      //       this.$message.error(res.msg);
      //       console.log("接口报错");
      //     }
      //   });
      // } else if (status == 1) {
      // saveAsphaltMaterialWarn(this.formData).then((res) => {
      saveWaterWarnMaterial(this.formData).then((res) => {
        if (res.errcode == 0) {
          this.yj_searchForm(this.getList, 1);
          this.$message.success("报警参数设置保存成功");
        } else {
          this.$message.error("报警参数设置-新增", res.msg);
          console.log("接口报错");
        }
      });

      // }
    },

    // 关闭新增编辑弹框
    resetForm() {
      this.dialogEditVisible = false;
    },

    // 骨料详情
    inputValue(val, table) {
      this.formData = {
        fId: this.detailData.fId, // 主键id
        fCompanyid: this.getList.companyId, // 施工单位id
        fCompanyname: this.showName, //施工单位
        fWaterwarn1: table[0].fOilstonewarn, // 水 低预警
        fWaterwarn2: table[1].fOilstonewarn, // 水 中预警
        fWaterwarn3: table[2].fOilstonewarn, // 水 高预警

        fCementwarn1: table[0].fPitchwarn, // 水泥 低预警
        fCementwarn2: table[1].fPitchwarn, // 水泥 中预警
        fCementwarn3: table[2].fPitchwarn, // 水泥 高预警

        fAggregatewarn1: table[0].fMineralwarn, // 骨料 低预警
        fAggregatewarn2: table[1].fMineralwarn, // 骨料 中预警
        fAggregatewarn3: table[2].fMineralwarn, // 骨料 高预警

        fExamine1: table[0].fExamine, // 流程 低预警
        fExamine2: table[1].fExamine, // 流程 中预警
        fExamine3: table[2].fExamine, // 流程 高预警
        fIsuse: table[0].fIsuse, // 1 是 0 否  是否启用
      };
    },

    // 多选方法
    selectionChange() {},
    // 排序方法
    sortChange() {},
    // 点击设备编码
    openDialog(row) {
      this.fId = row.F_Id;
      this.editText(this.fId);
    },
  },
};
</script>
  
<style scoped>
.saveBtn {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  margin-top: 15px;
  padding: 7px 40px 0px;
}

.temperatureScope {
  display: flex;
  /* width: 150px; */
}

.character {
  margin: 0 8px;
}

.customTable {
  display: flex;
  height: 100%;
  justify-content: flex-end;
  align-items: center;
  padding-right: 30px;
}

.customTable /deep/.cell {
  height: 100%;
  display: flex;
  align-items: center;
}

.customTable /deep/.el-button {
  width: 25px;
  display: flex;
  justify-content: center;
  align-items: center;
}

/* .customTableCenter /deep/.cell {
    height: 100%;
    display: flex;
    align-items: center;
} */

/* .customTableCenter /deep/.el-button {

    display: flex;
    justify-content: center;
    align-items: center;
} */
</style>